﻿using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace MapleLeaf.Pay.Pay {
    [Obsolete]
    public class EscPosPrinter : Stream, IEscPosPrinter {
       
        public string PrinterName { get; }

        [Obsolete]
        public Stream BaseStream {
            get {
                if (_BaseStream == null) {
                    _BaseStream = new FileStream(CreateFile(PrinterName, 1073741824, 3, 0, 3, 0, 0), FileAccess.ReadWrite);
                }
                return _BaseStream;
            }
        }

        // Token: 0x17000009 RID: 9
        // (get) Token: 0x0600007E RID: 126 RVA: 0x0000249F File Offset: 0x0000069F
        // (set) Token: 0x0600007F RID: 127 RVA: 0x000024A7 File Offset: 0x000006A7
        public Encoding Encoding { get; set; }

        // Token: 0x06000080 RID: 128 RVA: 0x000024B0 File Offset: 0x000006B0
       
        public void Write(params byte[] bytes) {
            BaseStream.Write(bytes, 0, bytes.Length);
        }

        // Token: 0x06000081 RID: 129 RVA: 0x000024C2 File Offset: 0x000006C2
        public void Write(string str) {
            if (!string.IsNullOrEmpty(str)) {
                Write(Encoding.GetBytes(str));
            }
        }

        // Token: 0x1700000A RID: 10
        // (get) Token: 0x06000082 RID: 130 RVA: 0x000024E1 File Offset: 0x000006E1
        public override bool CanRead {
            get {
                return BaseStream.CanRead;
            }
        }

        // Token: 0x1700000B RID: 11
        // (get) Token: 0x06000083 RID: 131 RVA: 0x000024EE File Offset: 0x000006EE
        public override bool CanSeek {
            get {
                return BaseStream.CanSeek;
            }
        }

        // Token: 0x1700000C RID: 12
        // (get) Token: 0x06000084 RID: 132 RVA: 0x000024FB File Offset: 0x000006FB
        public override bool CanWrite {
            get {
                return BaseStream.CanWrite;
            }
        }

        // Token: 0x1700000D RID: 13
        // (get) Token: 0x06000085 RID: 133 RVA: 0x00002508 File Offset: 0x00000708
        public override long Length {
            get {
                return BaseStream.Length;
            }
        }

        // Token: 0x1700000E RID: 14
        // (get) Token: 0x06000086 RID: 134 RVA: 0x00002515 File Offset: 0x00000715
        // (set) Token: 0x06000087 RID: 135 RVA: 0x00002522 File Offset: 0x00000722
        public override long Position {
            get => BaseStream.Position;
            set => BaseStream.Position = value;
        }

        // Token: 0x06000088 RID: 136
        [DllImport("kernel32")]
        public static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);

        // Token: 0x06000089 RID: 137 RVA: 0x00004744 File Offset: 0x00002944
        public override long Seek(long offset, SeekOrigin origin) {
            return BaseStream.Seek(offset, origin);
        }

        // Token: 0x0600008A RID: 138 RVA: 0x00002530 File Offset: 0x00000730
        public override void SetLength(long value) {
            BaseStream.SetLength(value);
        }

        // Token: 0x0600008B RID: 139 RVA: 0x00004760 File Offset: 0x00002960
        public override int Read(byte[] buffer, int offset, int count) {
            return BaseStream.Read(buffer, offset, count);
        }

        // Token: 0x0600008C RID: 140 RVA: 0x0000253E File Offset: 0x0000073E
        public override void Write(byte[] buffer, int offset, int count) {
            BaseStream.Write(buffer, offset, count);
        }

        // Token: 0x0600008D RID: 141 RVA: 0x0000254E File Offset: 0x0000074E
        public EscPosPrinter(string port) {
            Class18.LVfVa0hzXO4Jq();
            Encoding = Encoding.Default;
            PrinterName = port;
        }

        // Token: 0x0600008E RID: 142 RVA: 0x0000256D File Offset: 0x0000076D
        public override void Flush() {
            BaseStream.Flush();
        }

        // Token: 0x0600008F RID: 143 RVA: 0x0000257A File Offset: 0x0000077A
        public void Init() {
            Write(new byte[]
            {
                27,
                64
            });
        }

        // Token: 0x06000090 RID: 144 RVA: 0x00002592 File Offset: 0x00000792
        public override void Close() {
            BaseStream.Close();
            base.Close();
        }

        // Token: 0x06000091 RID: 145 RVA: 0x000025A5 File Offset: 0x000007A5
        protected override void Dispose(bool disposing) {
            BaseStream.Dispose();
            base.Dispose(disposing);
        }

        // Token: 0x06000092 RID: 146 RVA: 0x00004780 File Offset: 0x00002980
        public void Justify(EscPosJustify justify) {
            if (justify != EscPosJustify.Center) {
                if (justify != EscPosJustify.Right) {
                    byte[] array = new byte[3];
                    array[0] = 27;
                    array[1] = 97;
                    Write(array);
                }
                else {
                    Write(new byte[]
                    {
                        27,
                        97,
                        2
                    });
                }
            }
            else {
                Write(new byte[]
                {
                    27,
                    97,
                    1
                });
            }
        }

        // Token: 0x06000093 RID: 147 RVA: 0x000047E4 File Offset: 0x000029E4
        public void Size(EscPosTextSize size) {
            switch (size) {
                case EscPosTextSize.Bold:
                    Write(new byte[]
                    {
                    27,
                    33,
                    8
                    });
                    break;
                case EscPosTextSize.Height2:
                    Write(new byte[]
                    {
                    27,
                    33,
                    16
                    });
                    break;
                case EscPosTextSize.Width2:
                    Write(new byte[]
                    {
                    27,
                    33,
                    32
                    });
                    break;
                default: {
                        byte[] array = new byte[3];
                        array[0] = 27;
                        array[1] = 33;
                        Write(array);
                        break;
                    }
            }
        }

        // Token: 0x06000094 RID: 148 RVA: 0x000025B9 File Offset: 0x000007B9
        public void PaperOut(int n) {
            Write(new byte[]
            {
                27,
                100,
                (byte)n
            });
        }

        // Token: 0x06000095 RID: 149 RVA: 0x000025D6 File Offset: 0x000007D6
        public void CutPaper() {
            Write(new byte[]
            {
                27,
                109
            });
        }

        // Token: 0x04000020 RID: 32
        private Stream _BaseStream;
    }
}
